* ==============================================================================================
*            REPLICATION CODE FOR              
*           TERTYTCHNAYA, KATERINA. 2023.      
* "PREVENTIVE REPRESSION & PUBLIC OPINION"      
* WORLD POLITICS, FORTHCOMING.  ##
*
*This do file contains the code for recoding the data and replicating the analysis in Stata
* ==============================================================================================


clear
cd "~/WP_Replication" /*Set your own*/

*The following packages are needed*/
ssc install estout, replace
ssc install coefplot, replace
ssc install blindschemes  
set scheme plotplain

* ==============================================================================================
* 2017 LEVADA OMNIBUS 
* ==============================================================================================

* SET-UP THE DATA 
run Code/setup_obs.do 

* ==============================================================================================
* TABLE 1 
* ==============================================================================================
reg supp_dem i.auth_rev age agesq gender education i.vote_cast i.leader_attitudes logothers i.qOBL, cluster(qTO)
reg supp_dem i.type     age agesq gender education i.vote_cast i.leader_attitudes logothers i.qOBL, cluster(qTO)

* ==============================================================================================
* APPENDIX FIGURE B.1
* ==============================================================================================
reg dem_supp_dum i.auth_rev age agesq gender education i.vote_cast i.leader_attitudes logothers i.qOBL, cluster(qTO) 
est store Model1
reg dem_supp i.auth_rev age agesq gender education i.vote_cast i.leader_attitudes logothers i.qOBL, cluster(qTO) 
est store Model2
reg dem_supp i.auth_rev age agesq gender education logothers i.qOBL, cluster(qTO) 
est store Model3
reg dem_supp i.auth_rev age agesq gender education i.vote_cast logothers i.qOBL, cluster(qTO) 
est store Model4
reg dem_supp i.auth_rev age agesq gender education i.leader_attitudes logothers i.qOBL, cluster(qTO) 
est store Model5
reg supp_dem i.auth_rev age agesq gender education i.vote_cast i.leader_attitudes i.qOBL, cluster(qTO) 
est store Model6
reg supp_dem i.auth_rev age agesq gender education i.vote_cast i.leader_attitudes logothers civil_soc, cluster(qTO) 
est store Model7
coefplot Model1 Model2 Model3 Model4 Model5 Model6 Model7,keep(*.auth_rev)
graph save "Graph" "Graph_B1A.gph"

reg dem_supp_dum i.type age agesq gender education i.vote_cast i.leader_attitudes logothers i.qOBL, cluster(qTO) 
est store Model1
reg dem_supp i.type age agesq gender education i.vote_cast i.leader_attitudes logothers i.qOBL, cluster(qTO)  
est store Model2
reg dem_supp i.type age agesq gender education logothers i.qOBL, cluster(qTO) 
est store Model3
reg dem_supp i.type age agesq gender education i.vote_cast logothers i.qOBL, cluster(qTO) 
est store Model4
reg dem_supp i.type age agesq gender education i.leader_attitudes logothers i.qOBL, cluster(qTO)  
est store Model5
reg supp_dem i.type age agesq gender education i.vote_cast i.leader_attitudes i.qOBL, cluster(qTO) 
est store Model6
reg supp_dem i.type age agesq gender education i.vote_cast i.leader_attitudes logothers civil_soc, cluster(qTO) 
est store Model7
coefplot Model1 Model2 Model3 Model4 Model5 Model6 Model7,keep(*.type) 
graph save "Graph" "Graph_B1B.gph"

clear 

* ##############################################
* APPENDIX TABLE B.1
* ##############################################

use "Data/events_analysis.dta"

recode ethnic_republic .=0
recode offices_all .=0
recode offices_mj .=0
gen vote=100-ur_vote
gen logpop=log(pop2010)

codebook authorised_rev
recode authorised_rev (1=0) (0=1) (2=1), gen (unauthorized) /*Only treat authorized events as authorized */

tab arrests
recode arrests (0=0) (.=0) (1/866=1), gen (arrested)

/*Report Summary*/
codebook unauthorized offices_all offices_mj ethnic_republic logpop vote arrested civ_soc_rev, compact

*Replicate Table B.1* 
reg unauthorized offices_mj ethnic_republic logpop i.reg_code, cluster (locality)

reg unauthorized offices_all ethnic_republic logpop i.reg_code, cluster (locality)

reg unauthorized vote ethnic_republic logpop i.reg_code, cluster (locality)

reg arrested offices_mj ethnic_republic logpop i.reg_code, cluster (locality)

reg arrested offices_all ethnic_republic logpop i.reg_code, cluster (locality)

reg arrested vote ethnic_republic logpop i.reg_code, cluster (locality)

clear
